using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;


namespace V1.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class CommerceController : Controller
    {

        private readonly ILogger<CommerceController> _logger;
        public CommerceController(ILogger<CommerceController> logger)
        {
            _logger = logger;
        }
        [Route("admin")]//commcerce/admin
        [HttpPost]
        public IActionResult Login(string admin){
            return Json(new {name="admin",mima="lishuai"});
        }
        [Route("[action]")]
        [HttpPost]
        public IActionResult Login(User user){
            if(user==null)
                return NoContent();
            if(user.username=="admin"&&user.password=="lishuai")
                return Json(new {status=200});
            return Json(new {status=404,message="找不到用户名为"+user.username+"的用户!"});
            
        }
        [Route("[action]/{id?}")]
        [HttpGet]
        public IActionResult Login(int? id){
            return Json(new {a=id});
        }
        [HttpGet]
        public IEnumerable<WeatherForecast> Get()
        {
            var rng = new Random();
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55)
            })
            .ToArray();
        }
    }
}
